<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <!--<Avatar :icon="userAvator" style="margin-right: 5px;background-color: #5cadff;"/>-->
      <span style="margin-right: 10px;">{{username}}</span>
      <Icon :size="12" type="arrow-down-b"></Icon>
      <DropdownMenu slot="list">
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
  import './user.less'
  import {mapActions} from 'vuex'
  import Cookies from 'js-cookie'

  export default {
    name: 'User',
    props: {
      userAvator: {
        type: String,
        default: ''
      }
    },
    computed: {
      username() {
        return Cookies.get('username')
      }
    },
    methods: {
      ...mapActions('system/user', [
        'handleLogout'
      ]),
      handleClick(name) {
        switch (name) {
          case 'logout':
            this.handleLogout();
            location.reload()
/*            this.$router.push({
              name: 'login'
            })*/
            break
        }
      }
    }
  }
</script>
